package com.example.menu;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		generateHighScoresFile();
		return true;
	}

	public void startGame(View view) {
		Intent intent = new Intent(this, Game.class);
		startActivity(intent);
	}

	public void startScore(View view) {
		Intent intent = new Intent(this, Score.class);
		startActivity(intent);
	}

	public void startCredits(View view) {
		Intent intent = new Intent(this, Credits.class);
		startActivity(intent);
	}

	public void generateHighScoresFile() {
		File file = new File(Environment.getExternalStorageDirectory()
				+ "/squared/localHighScores.txt");
		FileWriter fw = null;
		BufferedWriter bw = null;
		PrintWriter pw = null;

		if (!file.exists()) {
			try {
				String theFile = "localHighScores";
				File direc = new File(Environment.getExternalStorageDirectory()
						+ "/squared/");
				if (direc.mkdir() || direc.isDirectory()) {
					file = new File(Environment.getExternalStorageDirectory()
							+ "/squared/" + theFile + ".txt");
					fw = new FileWriter(file.getAbsoluteFile());
					bw = new BufferedWriter(fw);
					pw = new PrintWriter(bw);
				}
				String content = "name;0;";
				for (int i=0; i<10; i++) {
					pw.write(content);
					pw.flush();
				}
			} catch (Exception e) {

			}
		}
	}
}
